package com.touchealth.test.suanfa;

/**
 * @author zhangyanqiang
 * @date 2020/10/22
 **/
public class SlidingWindow {

    public static int maxSubArray(int[] nums) {
        int max = Integer.MIN_VALUE;
        int curSum = 0;
        for(int i = 0; i< nums.length; i++) {
            curSum += nums[i];
            if(curSum > max) {
                max = curSum;
            }
            if (curSum < 0) {
                curSum = 0;
            }
        }
        return max;
    }

    public static void main(String[] args) {

        int[] arraNums = {-2,1,-3,4,-1,2,1,-5,4};
        System.out.println(maxSubArray(arraNums));
    }
}
